import os
import asyncio

import tweb
import ws_shell  # define WebShellHandler
# only import when os type is linux
if os.name == 'posix':
    import async_telnetd
else:
    async_telnetd = None
    print("[-] async_telnetd is not available on Windows")


# Serve static files
@tweb.route("/")
def index():
    return tweb.Response(headers={'Content-Type': 'text/html'},
        body='''<h1>Welcome to WebShell</h1>
<p><a href='/chat.html'>Chat Room</a></p>
<p><a href='/webshell.html'>Web Shell</a></p>''')

async def main():
    try:
        if async_telnetd:
            asyncio.create_task(async_telnetd.run(host="127.0.0.1", port=22222))
        await tweb.start_async(host="", port=28088, prefer_coroutine=True, resources={"/**": "."})
    except KeyboardInterrupt:
        print('web server shutdown')

if __name__ == '__main__':
    asyncio.run(main())

